﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Steam_Backup
{
    public partial class FrmAddGame : Form
    {
        private GameEntry m_gameEntry = null;

        internal GameEntry GameEntry
        {
            get { return m_gameEntry; }
            set { m_gameEntry = value; }
        }

        public FrmAddGame()
        {
            InitializeComponent();
        }

        private void FrmAddGame_Load(object sender, EventArgs e)
        {
            GameEntry gameEntry = new GameEntry();

            foreach (FileInfo fi in Utilities.GetFiles(Path.Combine(Utilities.GetSteamPath(), Utilities.s_szSteamApps)))
            {
                ListViewItem item = new ListViewItem(fi.Name);
                item.Tag = fi;
                lstFiles.Items.Add(item);
            }

            foreach (DirectoryInfo di in Utilities.GetFolders(Path.Combine(Utilities.GetSteamPath(), Utilities.s_szSteamApps, Utilities.s_szCommon)))
            {
                ListViewItem item = new ListViewItem(di.Name);
                item.Tag = di;
                lstGameFolder.Items.Add(item);
            }           
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            GameEntry gameEntry = new GameEntry();
            gameEntry.GameTitle = txtGameTitle.Text;
            if(lstGameFolder.SelectedItems.Count == 1)
            {
                gameEntry.GameFolder = lstGameFolder.SelectedItems[0].Text;
            }

            foreach (ListViewItem item in lstFiles.SelectedItems)
            {
                FileInfo fi = item.Tag as FileInfo;
                gameEntry.MainFiles.Add(fi.Name);
            }

            m_gameEntry = gameEntry;
        }   
    }
}
